import { contextBridge, ipcRenderer } from 'electron'

interface ElectronAPI {
  runOCR: (imageData: string) => Promise<any>
  openSoftware: (path: string) => Promise<any>
  checkPortStatus: (port: number) => Promise<boolean>
  openFileDialog: () => Promise<string[]>
  readFile: (path: string) => Promise<string>
  parseDirectory: (path: string) => Promise<any>
  selectDirectory: () => Promise<string>
  getImageMetadata: (path: string) => Promise<any>
  getConfig: () => Promise<any>
  openFile: (filePath: string) => Promise<void>
  readImg: (filePath: string) => Promise<void>
}

contextBridge.exposeInMainWorld('electronAPI', {
  runOCR: (imageData: string) => ipcRenderer.invoke('run-ocr', { imageData }),
  openSoftware: (path: string) => ipcRenderer.invoke('open-software', path),
  checkPortStatus: (port: number) => ipcRenderer.invoke('check-port-status', port),
  openFileDialog: () => ipcRenderer.invoke('open-file-dialog'),
  readFile: (path: string) => ipcRenderer.invoke('read-file', path),
  parseDirectory: (path: string) => ipcRenderer.invoke('parse-directory', path),
  selectDirectory: () => ipcRenderer.invoke('select-directory'),
  getImageMetadata: (path: string) => ipcRenderer.invoke('get-image-metadata', path),
  getConfig: () => ipcRenderer.invoke('get-config'),
  openFile: (filePath: string) => ipcRenderer.invoke('open-file', filePath),
  readImg: (filePath: string) => ipcRenderer.invoke('read-image', filePath)
} as ElectronAPI)